import java.util.*;

//new version
//lalalala
//jiji
public class ThreeSum {

	public static void main(String[] args) {
//		int array[]={-1,0,1,2,-1,-4};
		int array[]={0,0,0};
		System.out.println(threeSum(array));
	}

	public static List<List<Integer>> threeSum(int[] num) {
        List<List<Integer>> solution=new ArrayList<List<Integer>>();
        Arrays.sort(num);
        if (num.length<3) 
        	return solution;
        for (int i=0;i<num.length-2;i++)
        {
        	int start=i+1;
        	int end=num.length-1;
        	if (i==0 || num[i]!=num[i-1]) {
        		int negate=-num[i];
        		while (end>start)
        		{
        			if (num[start]+num[end]==negate) {
        				List<Integer> combine=new ArrayList<Integer> ();
        				combine.add(num[i]);
        				combine.add(num[start]);
        				combine.add(num[end]);
        				solution.add(combine);
        				start++;
        				end--;
        				while (num[start]==num[start-1] && start<end)
        					start++;
        				while (num[end]==num[end+1] && start<end)
        					end--;        				
        			}
        			else if (num[start]+num[end]>negate) {
        				end--;
        			}
        			else start++;	
        		}
        	}
        }
        return solution;
    }
}
